{	Problem: http://codeforces.ru/problemset/problem/61/C
	Verdict: Accepted
}
uses SysUtils;
const digits:array[1..36] of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
var n,b:longint; s,c:string;
function rom(num: int64): string;
const Nvals = 13; vals: array[1..Nvals] of word = (1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000); roms: array[1..Nvals] of string[2] = ('I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M');
var b: 1..Nvals;
begin
result := '';
b := Nvals;
while num > 0 do begin
  while vals[b] > num do dec(b);
  dec(num, vals[b]);
  result := result + roms[b]
end;
end;
function ptodec(p:longint; n:string):int64;
var current,step,index:int64; i,j:longint;
begin
step:=1;
current:=0;
for i:=length(n) downto 1 do begin
  for j:=1 to 36 do if digits[j]=n[i] then index:=j;
  current:=current+step*(index-1);
  step:=step*p;
end;
ptodec:=current;
end;
function dectop(p:longint; n:int64):string;
var current,count,step:int64; dig:array[1..1001] of int64;  s:string; i:longint;
begin
current:=n;
s:='';
if n=0 then s:='0';
count:=0;
while current>0 do begin
  inc(count);
  dig[count]:=current mod p;
  current:=current div p;
end;
step:=1;
for i:=count downto 1 do s:=s+digits[dig[i]+1];
dectop:=s;
end;
begin
read(n);
readln(c);
delete(c,1,1);
readln(s);
while (s[1]='0') and (length(s)>1) do delete(s,1,1);
if c='R' then begin
  writeln(rom(ptodec(n,s)));
end else begin
  b:=strtoint(c);
  writeln(dectop(b,ptodec(n,s)));
end;
end.